import { createRouter, createWebHashHistory } from "vue-router";
// 测试组件
import testlogin from "@pages/test/TestLogin.vue";
const routes = [
    // 默认跳转路由
    { path: '/', redirect: '/home' },
    { path: '/home', meta: { title: '主页' }, name: 'Home', component: () => import("@pages/home/Home.vue") },
    { path: '/about', meta: { title: '关于我们' }, name: 'About', component: () => import("@pages/about/About.vue") },
    // 文章列表
    { path: '/news', meta: { title: '文章列表' }, name: 'news', component: () => import("@pages/news/News.vue") },
    // 文章详情
    { path: '/news/:id', meta: { title: '文章详情' }, name: 'article', component: () => import("@pages/article/Article.vue") },
    { path: '/product', meta: { title: '产品信息' }, name: 'product', component: () => import("@pages/product/Product.vue") },
    { path: '/contact', meta: { title: '联系我们' }, name: 'contact', component: () => import("@pages/contact/Contact.vue") },
    { path: '/master', meta: { title: '后台管理' }, name: 'master', component: () => import("@pages/master/Master.vue") },
    { path: '/login', meta: { title: '登录' }, name: 'login', component: () => import("@pages/login/Login.vue") },
    { path: '/register', meta: { title: '注册' }, name: 'register', component: () => import("@pages/register/Register.vue") },
    { path: '/fogotpwd', meta: { title: '忘记密码' }, name: 'fogotpwd', component: () => import("@pages/fogotpwd/Fogotpwd.vue") },
    { path: '/resetpwd', meta: { title: '重置密码' }, name: 'resetpwd', component: () => import("@pages/resetpwd/ResetPwd.vue") },

    { path: '/singin', name: 'singin', component: () => import("@pages/singin/Singin.vue") },
    // 测试组件
    { path: '/test', name: 'test', component: () => import("@pages/test/Test.vue") },
    { path: '/testlogin', name: 'testlogin', component: testlogin },
    { path: '/edit', name: 'edit', component: () => import("@pages/edit/Edit.vue") },
]
const router = createRouter({
    history: createWebHashHistory(),
    routes
})

// 创建路由守卫
router.beforeEach((to, from, next) => {
    // 读取路由元信息设置标题
    if (to.meta.title) {
        document.title = to.meta.title + ' - 萌宠乐园';
    } else {
        document.title = '萌宠乐园';
    }
    next();
});


export default router